Import mojo
Import agfx

Class TTiled_ObjectGroup
	
	Field name:String
	Field width:Int
	Field height:Int
	Field properties:TProperties
	Field objects:ArrayList<TTiled_ObjectGroupObject>
	
	'------------------------------------------------------------------------------------
	' New
	'------------------------------------------------------------------------------------

	Method New(node:XMLElement)
		
		Self.properties		= New TProperties()		
		Self.objects		= New ArrayList<TTiled_ObjectGroupObject>
		
		If DEBUG Then Print("<OBJECT GROUP>")
		
		Self.name = node.GetAttribute("name")
		If DEBUG Then Print("      name: "+Self.name)
		
		Self.width = Int(node.GetAttribute("width"))
		If DEBUG Then Print("     width: "+Self.width)
		
		Self.height = Int(node.GetAttribute("height"))
		If DEBUG Then Print("     width: "+Self.height)
		
		Local obj:XMLElement

		For obj = EachIn node.Children
			
			Select obj.Name()
			
				Case "object"
					Local ogo:TTiled_ObjectGroupObject = New TTiled_ObjectGroupObject(obj)
					Self.objects.Add(ogo)
				Case "properties"
					If DEBUG Then Print(" <PROPERTIES>")
					Self.properties.Add(obj,"property","name","value")
					
			End Select
		Next
		
	End Method

	'------------------------------------------------------------------------------------
	' Find
	'------------------------------------------------------------------------------------
	Method GetObjectByName:TTiled_ObjectGroupObject(name:String)
		Local obj:TTiled_ObjectGroupObject
		For obj = EachIn Self.objects
			if obj.name=name Then Return obj
		Next

		Return null
	End Method
	
	Method GetObjectByType:TTiled_ObjectGroupObject(type:String)
		Local obj:TTiled_ObjectGroupObject
		For obj = EachIn Self.objects
			if obj.type=type Then Return obj
		Next

		Return null
	End Method
	
End Class